#include<stdio.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        printf("i am child process! pid:%d ppid:%d\n",getpid(),getppid());
        sleep(5);
        int* p = NULL; *p = 1; //制造异常退出
        exit(-1);
    }
    int status = 0;
    int pid = waitpid(id,&status,0);
    if(WIFEXITED(status))
    {
        printf("子进程正常退出！退出码：%d\n",WEXITSTATUS(status));
    }
    else
    {
        printf("子进程异常退出! core dump:%d 终止信号:%d \n",status>>7&1,status&0x7F);
    }
    return 0;
}